#!/bin/python
from xml.dom.minidom import parseString
from sgmllib import SGMLParser

root_path = "/home/dward/Desktop/Audit/allaccounts.qfx"

stats = {}
buffer = ""
file = open(root_path,"rb");
file.seek(0)
line = file.readline().strip()

while line != "":
    try:
        key, value = line.split(":")
        stats[key] = value
        line = file.readline().strip()
    except ValueError:
        pass

buffer = file.read()
file.close()


class RawNode(object):
    __slots__ = ["name","value","children"]
    def __init__(self, name):
        self.name = name
        self.value = None
        self.children = None
        
    def __getstate__(self):
        st = {}
        st["name"] = self.name
        st["value"] = self.value if self.value is not None else None
        st["children"] = self.children
        return st;
        
    def __setstate__(self,dic):
        self.name, self.value, self.children = dic["name"], dic["value"], dic["children"]
        

        
from lib.qfxparser import QFXParser


results = QFXParser()
results.feed(buffer)


import pickle
import pprint
rOut = open("results.txt","wb")
rOut.write(pprint.pformat(results.myQueue))
rOut.close()

tOut = open("results.pk","wb")
pickle.dump(results.myQueue,tOut )
tOut.close()

    